#!/usr/bin/env bash
NOWDIR=$(cd "$(dirname "$0")"; pwd)
ROOT=`echo $NOWDIR | sed "s|^$HOME|.|"`

sudo apt-get update
sudo apt-get install -y software-properties-common

sudo add-apt-repository ppa:chris-lea/redis-server -y
sudo add-apt-repository ppa:jonathonf/vim -y
sudo add-apt-repository ppa:jonathonf/python-3.6 -y
sudo apt-get update
sudo apt-get install -y tmux nodejs tree htop silversearcher-ag python3.6  tree ctags vim autojump mlocate zsh redis-server ruby locales
sudo gem install gist
sudo locale-gen zh_CN.UTF-8
sudo update-locale LC_ALL=zh_CN.UTF-8 LANG=zh_CN.UTF-8
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
sudo chsh -s /usr/bin/zsh $USER
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | sudo bash
#curl -Lo /usr/local/bin/rmate https://raw.github.com/textmate/rmate/master/bin/rmate
#chmod a+x /usr/local/bin/rmate

cd $NOWDIR
sudo cp ./redis/cache.conf /etc/redis/
sudo cp ./redis/redis-cache.service /etc/systemd/system/

sudo systemctl start redis-cache
sudo systemctl enable redis-cache

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

curl https://bootstrap.pypa.io/get-pip.py | sudo python3.6
sudo pip3 install virtualenv
virtualenv -p /usr/bin/python3.6 ~/.py3env


RUN(){
chmod +x $1
$1
}

cd $NOWDIR
RUN ./init_home.sh

sudo chown -R $USER:$USER ~
nvm install 8.9.0
nvm install node --latest-npm --reinstall-packages-from=node

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn -y
yarn config set registry 'https://registry.npm.taobao.org'

yarn global add coffeescript parcel-bundler

sudo rsync -av $NOWDIR/os/ /;

sudo git clone https://github.com/gmarik/Vundle.vim.git /usr/share/vim/vimfiles/bundle/Vundle.vim --depth=1;
sudo vim +PluginInstall +qall;

cd $NOWDIR


## 实际项目

RUN ./fckoa/install.sh
cd ~/workspace/caddy;RUN ./install.sh
sudo updatedb
